package apps.softtech.fastmarket;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import apps.softtech.Utility.RequestDataFromServer;

public class ActivityForgetPassword extends Activity{
	Button btForgetPassword;
	EditText etForgetPassword;
	String mEmail;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_forget_password);
		new RegisterGoogleCM(ActivityForgetPassword.this).registerGCM();
		
		etForgetPassword = (EditText)findViewById(R.id.etForgetPasswordEmail);
		btForgetPassword = (Button)findViewById(R.id.btForgetPassword);
		btForgetPassword.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mEmail=etForgetPassword.getText().toString().trim();
				if(mEmail.equals("")||mEmail.equals(null)){
					return;
					}
				new AsyncTaskForgetPassword().execute();
			}
		});
	}
	class AsyncTaskForgetPassword extends AsyncTask<Void, Void, Void>{
		ProgressDialog pd;
		int success;
		@Override
		protected void onPreExecute() {
			pd = new ProgressDialog(ActivityForgetPassword.this);
			pd.setMessage("Sending...");
			pd.show();
			super.onPreExecute();
		}
		@Override
		protected Void doInBackground(Void... params) {
			
//			String resString = new RequestDataFromServer().requestResetPassword(mEmail);
			
			try {
				JSONObject json = new JSONObject("");
				success = json.getInt("success");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			
			return null;
		}
		@Override
		protected void onPostExecute(Void result) {
			if(success!=1){
				Toast.makeText(ActivityForgetPassword.this, "No reset password, Try again!",Toast.LENGTH_LONG).show();
			}else{
				Toast.makeText(ActivityForgetPassword.this, "Please check your mail",Toast.LENGTH_LONG).show();
			}
			pd.dismiss();
			super.onPostExecute(result);
		}
		
	}
}
